raw_data = read.table("nba_scores.csv",sep = ",",header = TRUE)
elo_initials = read.table("nba_initial_elos.csv",sep = ",",header = TRUE)
year_list = c(2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020)
# list for saving hfa and weight in different years
hfa_list = c()
weight_list = c()
for (x in year_list){
home_wins = 0
games = 0
first_game_index = 1
scores = raw_data[which(raw_data$season==x),]
# Iterate through games - first index can be changed to eliminate early seasons where scores are extreme
for(i in first_game_index:nrow(scores)) {
# Count number of games that do not end in ties
if(scores$home_score[i] != scores$away_score[i]) { games = games + 1 }
# Count number of games where home team wins
if(scores$home_score[i] > scores$away_score[i]) { home_wins = home_wins + 1 }
}
home_win_prob = home_wins / games # Calculate home win probability where outcome was not a tie
hfa = -400*log10(1/home_win_prob - 1) # Calculate number of Elo points added to home team
hfa_list <- append(hfa_list,hfa)
starting_weight = 0 # Lower bound for weight ranges to be tested - generally set equal to 0
iterations = 100 # Number of k values to test
step_size = 0.1 # Amount to increment k by at each step
first_game_index = 1
# Initialize data frame to store k values and corresponding error
errors = data.frame(matrix(ncol = 2, nrow = iterations))
colnames(errors) = c("weight", "error")
errors$weight = starting_weight + (1:iterations)*step_size
errors$error = NA
# Iterate through all potential k values that are being tested
for(counter in 1:iterations) {
weight = starting_weight + counter*step_size # Calculate k value for current iteration
error = 0 # Reset error for current iteration
elos = read.table("nba_initial_elos.csv", header=TRUE, sep=",") # Reset initial Elo ratings
# Iterate through games - first index can be changed to eliminate early seasons in a league where early results tend to be extreme
for(i in first_game_index:nrow(scores)) {
# Find indices corresponding to home and away teams for current game
home_index = which(elos$team == scores$home_team[i])
away_index = which(elos$team == scores$away_team[i])
# Find home and away team Elo ratings
home_elo = elos$rating[home_index]
away_elo = elos$rating[away_index]
# Calculate home team win probability
win_prob = 1 / (10^((away_elo - (home_elo + hfa*scores$neutral[i]))/400) + 1)
# Calculate actual margin of victory - must be positive
score_diff = abs(scores$home_score[i] - scores$away_score[i])
# Determine home team result
if(scores$home_score[i] > scores$away_score[i]) {
home_result = 1 # Home team wins
} else if(scores$home_score[i] < scores$away_score[i]) {
home_result = 0 # Home team loses
} else {
home_result = 0.5 # Tie
}
# Add squared error between home result and predicted probability of home team winning to SSE
error = error + (home_result - win_prob)^2
# Calculate amount each team's Elo rating is adjusted by
home_elo_adjustment = weight * log(score_diff + 1) * (home_result - win_prob)
# Adjust Elo ratings - add point to winner and subtract points from loser
elos$rating[home_index] = elos$rating[home_index] + home_elo_adjustment
elos$rating[away_index] = elos$rating[away_index] - home_elo_adjustment
# Adjust Elo ratings at end of season to regress 1/3 of the way towards 1500
if(i < nrow(scores) && scores$season[i+1] > scores$season[i]) {
for(j in 1:nrow(elos)) {
if(scores$season[i] >= elos$inaugural_season[j]) {
elos$rating[j] = elos$rating[j] - (elos$rating[j] - 1500)/3
}
}
existing_teams = elos[which(elos$inaugural_season <= (scores$season[i] + 1)),]
expansion_adjustment = -1*(mean(existing_teams$rating) - 1500)
for(j in 1:nrow(elos)) {
if((scores$season[i] + 1) >= elos$inaugural_season[j]) {
elos$rating[j] = elos$rating[j] + expansion_adjustment
}
}
}
}
errors$error[counter] = error # Store error for current iteration
}
# Choose and print optimal weight based on value that had the lowest SSE
weight = errors$weight[which(errors$error == min(errors$error))]
weight_list <- append(weight_list,weight)
}
print(hfa_list)
## [1] 68.14165 64.13962 90.41023 85.61199 71.86992 76.27353 66.90464 77.83927
## [9] 79.29028 69.77472 76.19808 65.46320 80.18853 55.52015 53.14886 66.26620
## [17] 58.13276 60.99658 63.73097 32.62010 32.43418
print(weight_list)
## [1] 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0
## [16] 10.0 9.9 10.0 10.0 10.0 10.0
write.table(as.data.frame(hfa_list),file="hfa.csv", quote=F,sep=",",row.names=F)
write.table(as.data.frame(weight_list),file="weight.csv", quote=F,sep=",",row.names=F)
hfa_list=read.csv("hfa.csv")
weight_list=read.csv("weight.csv")
#Only use data from 2000 to 2020
scores = raw_data[which(raw_data$season > 1999),]
#Get all the team name
team_name=unique(scores$home_team)
#Combine hfa and weight into dataframe
Adjustment<-cbind(hfa_list,weight_list)
# Use list to store average elo ratings for each year from 2000 to 2020
stack=list()
for(teamN in team_name){
inital_year=2000
# Optimal weight from code above. If the above code is run first, the line below can be commented out. Otherwise, you can type the optimal k-value below without needing to run the chunk of code above.
for(i in 1:nrow(Adjustment)){
weight = Adjustment[i,"weight_list"]
hfa =Adjustment[i,"hfa_list"]
# Select team and season to follow for a period of time
team = teamN
first_season = inital_year
last_season = inital_year
inital_year=inital_year+1
# Read in initial team Elo ratings and history of games
elos = read.table("nba_initial_elos.csv", header=TRUE, sep=",")
scores =raw_data[which(raw_data$season<=first_season),]
# Create data frame to store information for team specified above
team_results = data.frame(matrix(ncol = 8, nrow = 0))
colnames(team_results) = c("opponent", "pregame_elo", "win_probability", "result", "team_score", "opponent_score", "elo_adjustment", "postgame_elo")
# Iterate through all games in the sport's history
for(i in 1:nrow(scores)) {
# Find indices corresponding to home and away teams for current game
home_index = which(elos$team == scores$home_team[i])
away_index = which(elos$team == scores$away_team[i])
# Find home and away team Elo ratings
home_elo = elos$rating[home_index]
away_elo = elos$rating[away_index]
# Calculate home team win probability
win_prob = 1 / (10^((away_elo - (home_elo + hfa*scores$neutral[i]))/400) + 1)
# Calculate actual margin of victory - must be positive
score_diff = abs(scores$home_score[i] - scores$away_score[i])
# Determine home team result
if(scores$home_score[i] > scores$away_score[i]) {
home_result = 1 # Home team wins
} else if(scores$home_score[i] < scores$away_score[i]) {
home_result = 0 # Home team loses
} else {
home_result = 0.5 # Tie
}
# Calculate amount each team's Elo rating is adjusted by
home_elo_adjustment = weight * log(score_diff + 1) * (home_result - win_prob)
# Adjust Elo ratings - add point to winner and subtract points from loser
elos$rating[home_index] = elos$rating[home_index] + home_elo_adjustment
elos$rating[away_index] = elos$rating[away_index] - home_elo_adjustment
# Add game information to team result data frame for each team game of the team specified above if team and season both match
if(scores$season[i] >= first_season & scores$season[i] <= last_season & (scores$home_team[i] == team | scores$away_team[i] == team)) {
if(scores$home_team[i] == team) { # If specified team was at home
team_results[nrow(team_results) + 1,] = c(scores$away_team[i], elos$rating[home_index] - home_elo_adjustment, win_prob, home_result, scores$home_score[i], scores$away_score[i], home_elo_adjustment, elos$rating[home_index])
} else { # If specified team was away
team_results[nrow(team_results) + 1,] = c(scores$home_team[i], elos$rating[away_index] + home_elo_adjustment, 1-win_prob, 1-home_result, scores$away_score[i], scores$home_score[i], -1*home_elo_adjustment, elos$rating[away_index])
}
}
# Adjust Elo ratings at end of season to regress 1/3 of the way towards 1500
if(i < nrow(scores) && scores$season[i+1] > scores$season[i]) { # New season
for(j in 1:nrow(elos)) { # For each team
if(scores$season[i] >= elos$inaugural_season[j]) { # Check if team existed
# Move each team's Elo rating back towards 1500 by 1/3 of the difference
elos$rating[j] = elos$rating[j] - (elos$rating[j] - 1500)/3
}
}
# Identify all teams that existed at beginning of following season
existing_teams = elos[which(elos$inaugural_season <= (scores$season[i] + 1)),]
# Calculate amount each team's Elo rating must be adjusted by to make mean 1500
expansion_adjustment = -1*(mean(existing_teams$rating) - 1500)
# Perform expansion adjustment on teams that existed at beginning of following season
for(j in 1:nrow(elos)) { # For each team
if((scores$season[i] + 1) >= elos$inaugural_season[j]) { # Check if team existed
elos$rating[j] = elos$rating[j] + expansion_adjustment # Update ratings if so
}
}
}
}
# Change data type to numeric
temp=transform(team_results,postgame_elo=as.numeric(postgame_elo))
# Store the elo into the list
stack=append(stack,mean(temp$postgame_elo))
}
}
# Create a dataframe that contains teams' name and their elo rating for each year
df=data.frame(matrix(ncol=30,nrow=21))
colnames(df)=team_name
team_number=1
row=1
for(i in 1:length(stack)){
df[row,team_number]=stack[i]
row=row+1
if(i%%21==0){
team_number=team_number+1
row=1
}
}
## Remove nan value in the elo rating
## Since these nan values are caused by no games or team reorganize so we initial it as the initial elo ratings
df[1,30]=1400
df[2,30]=1400
df[3,"Charlotte Hornets"]=1400
df[4,"Charlotte Hornets"]=1400
df
## Orlando Magic Atlanta Hawks Brooklyn Nets Toronto Raptors New York Knicks
## 1 1512.578 1348.977 1382.767 1529.481 1552.360
## 2 1519.962 1385.598 1537.059 1520.403 1438.110
## 3 1502.088 1414.345 1601.256 1383.043 1430.943
## 4 1362.400 1388.205 1578.669 1396.073 1455.673
## 5 1420.943 1287.624 1465.098 1420.775 1435.460
## 6 1408.274 1297.400 1550.400 1395.466 1353.064
## 7 1487.848 1379.312 1504.171 1480.783 1393.329
## 8 1574.085 1435.444 1438.920 1530.162 1349.833
## 9 1660.072 1531.681 1434.610 1441.936 1393.674
## 10 1671.369 1592.194 1282.836 1470.645 1388.507
## 11 1642.035 1547.372 1329.773 1366.798 1476.039
## 12 1567.552 1540.793 1332.073 1357.368 1492.788
## 13 1361.786 1530.214 1493.860 1413.401 1593.159
## 14 1320.602 1477.171 1502.553 1540.488 1471.181
## 15 1330.203 1625.417 1461.463 1573.115 1342.797
## 16 1420.435 1566.538 1359.656 1593.502 1386.316
## 17 1394.437 1512.875 1294.377 1594.329 1415.081
## 18 1369.359 1379.129 1373.786 1644.333 1414.033
## 19 1444.077 1348.934 1452.529 1655.317 1307.248
## 20 1486.428 1355.032 1473.297 1679.725 1311.988
## 21 1392.213 1505.946 1578.862 1528.453 1483.369
## Dallas Mavericks Houston Rockets San Antonio Spurs Chicago Bulls Utah Jazz
## 1 1591.778 1537.814 1675.189 1248.654 1619.731
## 2 1635.241 1456.316 1671.600 1281.701 1558.476
## 3 1704.404 1504.038 1681.439 1352.033 1560.562
## 4 1621.615 1561.089 1695.795 1346.120 1505.034
## 5 1638.867 1567.068 1722.777 1461.916 1425.894
## 6 1692.314 1505.854 1702.870 1498.784 1440.638
## 7 1714.482 1573.407 1687.105 1568.286 1581.448
## 8 1628.145 1606.177 1668.317 1473.430 1623.492
## 9 1570.834 1621.814 1624.047 1471.621 1596.866
## 10 1603.383 1560.179 1595.411 1488.580 1602.854
## 11 1650.893 1505.318 1672.686 1629.686 1532.371
## 12 1605.043 1520.907 1662.311 1675.369 1493.342
## 13 1499.577 1545.655 1700.623 1560.450 1519.892
## 14 1569.809 1613.511 1703.097 1528.041 1411.149
## 15 1598.562 1634.076 1675.839 1568.128 1429.687
## 16 1530.417 1533.151 1748.373 1511.650 1515.781
## 17 1441.790 1605.544 1707.823 1483.867 1578.967
## 18 1409.193 1698.182 1588.077 1406.540 1568.108
## 19 1431.524 1630.326 1548.938 1318.918 1596.887
## 20 1550.709 1618.926 1495.799 1359.948 1593.988
## 21 1544.804 1397.140 1502.575 1426.581 1646.461
## Portland Trailblazers Golden State Warriors Memphis Grizzlies
## 1 1642.740 1312.091 1362.745
## 2 1570.541 1320.778 1329.445
## 3 1599.260 1428.947 1372.699
## 4 1514.750 1468.902 1537.364
## 5 1441.475 1422.575 1556.248
## 6 1345.612 1473.983 1560.822
## 7 1374.908 1486.709 1406.928
## 8 1475.123 1581.835 1355.412
## 9 1566.178 1443.175 1322.824
## 10 1583.983 1381.520 1458.657
## 11 1552.494 1428.487 1527.733
## 12 1523.934 1451.575 1579.043
## 13 1450.839 1514.690 1633.213
## 14 1578.012 1599.087 1576.986
## 15 1617.572 1729.056 1631.497
## 16 1536.882 1819.362 1532.061
## 17 1522.617 1776.272 1513.912
## 18 1560.228 1720.183 1402.190
## 19 1607.011 1678.043 1417.907
## 20 1511.423 1420.175 1451.602
## 21 1525.967 1463.331 1527.203
## Philadelphia 76ers Boston Celtics Cleveland Cavaliers Charlotte Hornets
## 1 1626.664 1445.540 1413.022 1579.744
## 2 1544.190 1534.978 1384.473 1534.144
## 3 1552.466 1532.924 1296.688 1400.000
## 4 1465.920 1446.751 1373.631 1400.000
## 5 1456.548 1491.084 1500.606 1369.137
## 6 1469.158 1466.464 1547.565 1346.137
## 7 1418.231 1377.199 1575.397 1398.292
## 8 1477.296 1653.579 1539.650 1412.513
## 9 1500.772 1710.315 1696.196 1438.418
## 10 1416.064 1628.131 1725.939 1509.773
## 11 1481.746 1663.776 1376.380 1450.106
## 12 1547.014 1577.060 1361.565 1276.994
## 13 1447.657 1529.151 1339.011 1244.856
## 14 1306.377 1404.732 1375.072 1428.789
## 15 1266.877 1414.549 1568.167 1449.779
## 16 1231.525 1552.119 1672.535 1504.589
## 17 1320.339 1583.494 1645.776 1511.207
## 18 1524.922 1609.203 1580.703 1465.218
## 19 1597.386 1589.661 1363.455 1481.095
## 20 1588.602 1643.199 1322.577 1401.040
## 21 1597.592 1555.697 1360.845 1452.479
## Miami Heat Oklahoma City Thunder Los Angeles Lakers Denver Nuggets
## 1 1580.383 1516.280 1660.021 1466.015
## 2 1451.793 1565.449 1712.430 1401.871
## 3 1403.929 1516.953 1612.539 1316.763
## 4 1446.529 1490.728 1640.088 1473.772
## 5 1642.723 1591.700 1522.708 1526.876
## 6 1622.909 1460.803 1511.214 1537.941
## 7 1532.870 1450.857 1537.886 1520.907
## 8 1333.792 1338.357 1638.245 1573.056
## 9 1447.051 1306.026 1739.274 1611.590
## 10 1521.518 1530.456 1691.358 1628.885
## 11 1660.722 1607.454 1663.049 1587.122
## 12 1683.304 1685.590 1596.489 1574.166
## 13 1715.831 1701.643 1531.048 1622.817
## 14 1672.894 1687.167 1413.574 1511.743
## 15 1495.546 1578.792 1353.524 1438.651
## 16 1531.055 1645.570 1281.701 1423.737
## 17 1499.393 1594.343 1351.878 1471.559
## 18 1521.597 1553.924 1419.346 1534.241
## 19 1478.437 1586.461 1481.179 1601.815
## 20 1580.975 1571.687 1636.367 1598.682
## 21 1537.013 1425.462 1619.727 1602.220
## Phoenix Suns Los Angeles Clippers Washington Wizards Detroit Pistons
## 1 1595.597 1346.182 1342.800 1442.917
## 2 1519.109 1498.220 1421.632 1527.419
## 3 1522.861 1414.939 1459.551 1588.445
## 4 1433.860 1414.790 1367.160 1620.196
## 5 1641.622 1451.457 1474.865 1627.845
## 6 1657.980 1544.845 1496.490 1713.694
## 7 1674.107 1509.988 1519.611 1628.539
## 8 1647.815 1411.232 1482.104 1660.406
## 9 1561.894 1312.553 1348.677 1539.739
## 10 1598.623 1363.242 1353.936 1387.911
## 11 1544.909 1377.159 1320.537 1379.259
## 12 1504.812 1536.857 1309.898 1377.531
## 13 1422.806 1629.449 1383.476 1396.885
## 14 1515.269 1648.869 1501.079 1397.924
## 15 1544.841 1653.669 1543.050 1387.393
## 16 1382.318 1625.293 1493.885 1498.609
## 17 1343.418 1607.481 1545.416 1483.242
## 18 1324.254 1535.641 1541.475 1471.678
## 19 1280.644 1537.639 1447.112 1483.617
## 20 1412.429 1618.544 1396.223 1409.682
## 21 1628.820 1632.801 1412.243 1361.860
## Indiana Pacers Minnesota Timberwolves Milwaukee Bucks Sacramento Kings
## 1 1525.005 1559.074 1573.391 1627.307
## 2 1496.920 1601.366 1555.892 1677.376
## 3 1552.680 1568.133 1482.015 1670.818
## 4 1622.613 1644.186 1503.928 1659.236
## 5 1551.911 1558.584 1435.059 1595.298
## 6 1535.426 1498.267 1444.227 1514.539
## 7 1469.696 1447.527 1421.174 1482.851
## 8 1429.621 1319.242 1368.186 1450.946
## 9 1451.712 1351.452 1414.023 1346.882
## 10 1415.962 1291.827 1497.597 1341.896
## 11 1467.955 1296.799 1477.586 1319.888
## 12 1550.653 1411.930 1480.390 1387.802
## 13 1584.230 1421.391 1475.542 1377.870
## 14 1623.789 1523.177 1301.804 1398.588
## 15 1476.973 1348.713 1437.570 1411.745
## 16 1532.926 1339.507 1424.681 1425.552
## 17 1502.295 1430.135 1470.314 1415.515
## 18 1529.064 1530.215 1509.227 1348.429
## 19 1577.161 1500.547 1661.946 1456.291
## 20 1554.705 1413.028 1713.567 1445.720
## 21 1502.121 1334.271 1622.999 1440.451
## New Orleans Pelicans
## 1 1400.000
## 2 1400.000
## 3 1489.062
## 4 1509.359
## 5 1356.579
## 6 1441.606
## 7 1459.113
## 8 1604.971
## 9 1596.136
## 10 1476.641
## 11 1526.021
## 12 1408.431
## 13 1407.933
## 14 1431.714
## 15 1495.990
## 16 1448.355
## 17 1417.812
## 18 1528.619
## 19 1511.747
## 20 1454.883
## 21 1486.189
write.csv(df,"elo.csv",row.names = FALSE)
df=read.csv("elo.csv")
# List for storing mean,median,and sd
mean_stack=list()
sd_stack=list()
median_stack=list()
# Calculate mean, median,and sd
for(i in colnames(df)){
mean_stack=append(mean_stack,mean(df[,i]))
sd_stack=append(sd_stack,sd(df[,i]))
median_stack=append(median_stack,median(df[,i]))
}
# Store everything in the descriptive_stat dataframe
mean_df=as.data.frame(do.call(rbind,mean_stack))
colnames(mean_df)="mean"
sd_df=as.data.frame(do.call(rbind,sd_stack))
colnames(sd_df)="sd"
median_df=as.data.frame(do.call(rbind,median_stack))
colnames(median_df)="median"
descriptive_stat=cbind(colnames(df),mean_df,sd_df,median_df)
colnames(descriptive_stat)=c("team","mean","sd","median")
write.csv(descriptive_stat,"descriptive.csv",row.names = FALSE)
descriptive_stat=read.csv("descriptive.csv")
# Reset the team name since the names have some changes
team_name=colnames(df)
library(ggplot2)
df$year=2000:2020
#Create plot of Elo ratings for different team from 2000-2020
for(i in team_name){
plot.ts(df[,i],xlab = "Year from 2000 to 2020", ylab = "Elo Rating",main = paste("Team: ",i))
#axis(1,df$year)
}
## Calculate autocrrelation and durbinWatsontest for the linear
model
library(car)
## Loading required package: carData
for (i in team_name){
cat(paste("Team: ",i))
cat("\n")
#Construct the linear model
cur_model=lm(df[,i]~df[,"year"])
# formating
print(durbinWatsonTest(cur_model))
cat("\n")
cat("\n")
}
## Team: Orlando.Magic
## lag Autocorrelation D-W Statistic p-value
## 1 0.7078625 0.581168 0
## Alternative hypothesis: rho != 0
##
##
## Team: Atlanta.Hawks
## lag Autocorrelation D-W Statistic p-value
## 1 0.6832184 0.6229795 0
## Alternative hypothesis: rho != 0
##
##
## Team: Brooklyn.Nets
## lag Autocorrelation D-W Statistic p-value
## 1 0.4444372 0.8767611 0
## Alternative hypothesis: rho != 0
##
##
## Team: Toronto.Raptors
## lag Autocorrelation D-W Statistic p-value
## 1 0.5082855 0.8085398 0
## Alternative hypothesis: rho != 0
##
##
## Team: New.York.Knicks
## lag Autocorrelation D-W Statistic p-value
## 1 0.3163093 1.187897 0.02
## Alternative hypothesis: rho != 0
##
##
## Team: Dallas.Mavericks
## lag Autocorrelation D-W Statistic p-value
## 1 0.3304898 1.163481 0.018
## Alternative hypothesis: rho != 0
##
##
## Team: Houston.Rockets
## lag Autocorrelation D-W Statistic p-value
## 1 0.1085938 1.329416 0.06
## Alternative hypothesis: rho != 0
##
##
## Team: San.Antonio.Spurs
## lag Autocorrelation D-W Statistic p-value
## 1 0.6529772 0.5509981 0
## Alternative hypothesis: rho != 0
##
##
## Team: Chicago.Bulls
## lag Autocorrelation D-W Statistic p-value
## 1 0.7297002 0.3983664 0
## Alternative hypothesis: rho != 0
##
##
## Team: Utah.Jazz
## lag Autocorrelation D-W Statistic p-value
## 1 0.55544 0.7217189 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Portland.Trailblazers
## lag Autocorrelation D-W Statistic p-value
## 1 0.5259033 0.8019058 0
## Alternative hypothesis: rho != 0
##
##
## Team: Golden.State.Warriors
## lag Autocorrelation D-W Statistic p-value
## 1 0.6095012 0.6132759 0
## Alternative hypothesis: rho != 0
##
##
## Team: Memphis.Grizzlies
## lag Autocorrelation D-W Statistic p-value
## 1 0.6370672 0.7025395 0
## Alternative hypothesis: rho != 0
##
##
## Team: Philadelphia.76ers
## lag Autocorrelation D-W Statistic p-value
## 1 0.654117 0.5185056 0
## Alternative hypothesis: rho != 0
##
##
## Team: Boston.Celtics
## lag Autocorrelation D-W Statistic p-value
## 1 0.4408933 1.093947 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Cleveland.Cavaliers
## lag Autocorrelation D-W Statistic p-value
## 1 0.5886311 0.7720176 0
## Alternative hypothesis: rho != 0
##
##
## Team: Charlotte.Hornets
## lag Autocorrelation D-W Statistic p-value
## 1 0.4752125 0.8775541 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Miami.Heat
## lag Autocorrelation D-W Statistic p-value
## 1 0.4750486 1.021841 0.012
## Alternative hypothesis: rho != 0
##
##
## Team: Oklahoma.City.Thunder
## lag Autocorrelation D-W Statistic p-value
## 1 0.5584059 0.7497431 0
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Lakers
## lag Autocorrelation D-W Statistic p-value
## 1 0.7069464 0.4759136 0
## Alternative hypothesis: rho != 0
##
##
## Team: Denver.Nuggets
## lag Autocorrelation D-W Statistic p-value
## 1 0.6666633 0.6630547 0
## Alternative hypothesis: rho != 0
##
##
## Team: Phoenix.Suns
## lag Autocorrelation D-W Statistic p-value
## 1 0.4045231 0.9464731 0.006
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Clippers
## lag Autocorrelation D-W Statistic p-value
## 1 0.5917471 0.8028749 0
## Alternative hypothesis: rho != 0
##
##
## Team: Washington.Wizards
## lag Autocorrelation D-W Statistic p-value
## 1 0.5851073 0.7680514 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Detroit.Pistons
## lag Autocorrelation D-W Statistic p-value
## 1 0.6492766 0.5486223 0
## Alternative hypothesis: rho != 0
##
##
## Team: Indiana.Pacers
## lag Autocorrelation D-W Statistic p-value
## 1 0.4859199 1.015781 0.012
## Alternative hypothesis: rho != 0
##
##
## Team: Minnesota.Timberwolves
## lag Autocorrelation D-W Statistic p-value
## 1 0.6335969 0.7228651 0
## Alternative hypothesis: rho != 0
##
##
## Team: Milwaukee.Bucks
## lag Autocorrelation D-W Statistic p-value
## 1 0.5960961 0.6605117 0
## Alternative hypothesis: rho != 0
##
##
## Team: Sacramento.Kings
## lag Autocorrelation D-W Statistic p-value
## 1 0.790246 0.3386508 0
## Alternative hypothesis: rho != 0
##
##
## Team: New.Orleans.Pelicans
## lag Autocorrelation D-W Statistic p-value
## 1 0.254611 1.455674 0.136
## Alternative hypothesis: rho != 0
library(car)
# Create a list to store the optimal order
opt_order=list()
for(i in team_name){
# Construct the autoregressive model
model_time=ar.ols(df[,i],order.max = 9, demean = F, intercept = T)
# formating
cat(paste("\nTeam: ",i),"\n")
cat("\n")
print(model_time)
cat("\n")
cat("\n")
# store the order into list
opt_order=append(opt_order,model_time$order)
}
##
## Team: Orlando.Magic
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 1.2610 -0.3175 -0.1058 0.8743 0.3506 -0.6165 0.4616 0.3090
## 9
## 0.9459
##
## Intercept: -3291 (1748)
##
## Order selected 9 sigma^2 estimated as 1766
##
##
##
## Team: Atlanta.Hawks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.2218 0.1476 -0.4475 -0.1623 -0.0099 0.5228 -0.6158 0.2043
## 9
## -0.5410
##
## Intercept: 2481 (442.1)
##
## Order selected 9 sigma^2 estimated as 912
##
##
##
## Team: Brooklyn.Nets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## -0.7649 -0.3135 -0.5825 -0.6694 -0.6194 -0.0945 0.3299 0.0618
## 9
## -0.5136
##
## Intercept: 5879 (805.6)
##
## Order selected 9 sigma^2 estimated as 526.1
##
##
##
## Team: Toronto.Raptors
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3
## 0.8775 -0.0234 -0.1993
##
## Intercept: 521.3 (252.3)
##
## Order selected 3 sigma^2 estimated as 3439
##
##
##
## Team: New.York.Knicks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7
## 0.2437 -0.4389 -0.4524 0.0601 -0.2215 -0.5193 -0.5942
##
## Intercept: 4167 (710.1)
##
## Order selected 7 sigma^2 estimated as 1401
##
##
##
## Team: Dallas.Mavericks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5
## 1.0729 -0.8805 0.4968 0.2662 -0.0231
##
## Intercept: 85.29 (319.4)
##
## Order selected 5 sigma^2 estimated as 1568
##
##
##
## Team: Houston.Rockets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.3829 -0.3951 -0.0897 -0.6887 0.7449 -0.7839
##
## Intercept: 2875 (742.3)
##
## Order selected 6 sigma^2 estimated as 2253
##
##
##
## Team: San.Antonio.Spurs
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4
## 0.8795 -0.2906 0.0830 -0.8105
##
## Intercept: 1898 (628)
##
## Order selected 4 sigma^2 estimated as 1360
##
##
##
## Team: Chicago.Bulls
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 1.0809 -0.5619 0.3369 -0.2825 0.1049 0.0185 -0.6465 0.2785
##
## Intercept: 1010 (394.6)
##
## Order selected 8 sigma^2 estimated as 1701
##
##
##
## Team: Utah.Jazz
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.2328 -0.2364 -0.1576 -0.2025 -0.4816 0.0339 -0.7020 0.1963
##
## Intercept: 3546 (1148)
##
## Order selected 8 sigma^2 estimated as 845
##
##
##
## Team: Portland.Trailblazers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## -0.1902 -0.6522 -0.0369 0.0602 0.1058 -0.2094 0.4272 0.0097
## 9
## -0.1045
##
## Intercept: 2476 (618.2)
##
## Order selected 9 sigma^2 estimated as 559.2
##
##
##
## Team: Golden.State.Warriors
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.4948 0.4338 0.0332 -0.5788 -0.0925 -0.1548 0.2395 0.9725
##
## Intercept: -433.3 (372)
##
## Order selected 8 sigma^2 estimated as 1944
##
##
##
## Team: Memphis.Grizzlies
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.2244 0.5259 -0.4781 -0.6063 0.2779 0.1321 -0.1747 -0.3895
## 9
## 0.5808
##
## Intercept: 1399 (15.46)
##
## Order selected 9 sigma^2 estimated as 0.7429
##
##
##
## Team: Philadelphia.76ers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 1.3727 -1.5085 0.9408 -0.9177 0.1059 0.2476 -0.5599 0.6490
## 9
## 0.3165
##
## Intercept: 465.1 (546.7)
##
## Order selected 9 sigma^2 estimated as 828.4
##
##
##
## Team: Boston.Celtics
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7
## 0.0071 -0.4211 -0.0075 -0.4380 -0.2072 -0.5501 0.0328
##
## Intercept: 4017 (407.9)
##
## Order selected 7 sigma^2 estimated as 669.2
##
##
##
## Team: Cleveland.Cavaliers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.3361 -0.6242 -0.2406 -0.7476 -0.2722 -0.2299 -0.3262 0.1527
## 9
## -0.4456
##
## Intercept: 5112 (1603)
##
## Order selected 9 sigma^2 estimated as 2646
##
##
##
## Team: Charlotte.Hornets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2
## 0.6590 -0.4131
##
## Intercept: 1072 (269.2)
##
## Order selected 2 sigma^2 estimated as 3134
##
##
##
## Team: Miami.Heat
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## -0.0955 0.1991 -0.4512 -0.0397 -0.4760 -0.3900 0.2905 -0.3326
## 9
## -0.2339
##
## Intercept: 3953 (682)
##
## Order selected 9 sigma^2 estimated as 459.8
##
##
##
## Team: Oklahoma.City.Thunder
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## -0.2071 0.3221 0.0814 -0.3042 -0.5986 0.4257 0.0392 -0.4389
## 9
## -0.0793
##
## Intercept: 2766 (248)
##
## Order selected 9 sigma^2 estimated as 418.8
##
##
##
## Team: Los.Angeles.Lakers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.1666 0.6637 0.0488 -0.6747 0.0370 0.1771 -0.5461 0.2466
## 9
## 0.4365
##
## Intercept: 627.5 (238.9)
##
## Order selected 9 sigma^2 estimated as 344.4
##
##
##
## Team: Denver.Nuggets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5
## 1.0182 -0.5624 0.0248 0.1845 -0.3073
##
## Intercept: 990.7 (304.3)
##
## Order selected 5 sigma^2 estimated as 1193
##
##
##
## Team: Phoenix.Suns
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.6631
##
## Intercept: 509.2 (258.9)
##
## Order selected 1 sigma^2 estimated as 7621
##
##
##
## Team: Los.Angeles.Clippers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.4756 0.3389 -0.0355 -0.3893 -0.0447 0.2167 0.2598 -0.1615
## 9
## 0.1127
##
## Intercept: 399.8 (285.8)
##
## Order selected 9 sigma^2 estimated as 788.1
##
##
##
## Team: Washington.Wizards
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.8659 -0.5565 0.2669 -0.3712 -0.5637 -0.0930 0.3938 -0.4912
## 9
## -0.2768
##
## Intercept: 2614 (537.3)
##
## Order selected 9 sigma^2 estimated as 99.77
##
##
##
## Team: Detroit.Pistons
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.7351 -0.3741 0.3139 -0.2870 0.1826 -0.3727 0.1043 0.1706
##
## Intercept: 743.8 (263.8)
##
## Order selected 8 sigma^2 estimated as 665.4
##
##
##
## Team: Indiana.Pacers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4
## 0.3621 0.1419 -0.2554 -0.2929
##
## Intercept: 1580 (404.4)
##
## Order selected 4 sigma^2 estimated as 1618
##
##
##
## Team: Minnesota.Timberwolves
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## 0.4183 0.0294 -1.3940 0.9422 0.0671 -1.0643 -0.2245 1.6322
## 9
## -1.3629
##
## Intercept: 2780 (602.7)
##
## Order selected 9 sigma^2 estimated as 377.1
##
##
##
## Team: Milwaukee.Bucks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.6983
##
## Intercept: 449.6 (253.3)
##
## Order selected 1 sigma^2 estimated as 4772
##
##
##
## Team: Sacramento.Kings
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## -0.0177 0.0470 -0.5020 0.1371 0.1307 -0.6452 0.5042 0.0634
## 9
## -0.3674
##
## Intercept: 2329 (600.8)
##
## Order selected 9 sigma^2 estimated as 405.3
##
##
##
## Team: New.Orleans.Pelicans
##
##
## Call:
## ar.ols(x = df[, i], order.max = 9, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6 7 8
## -0.4686 -0.3205 -0.2445 -0.0419 -0.5930 -0.5498 0.1190 -0.2052
## 9
## -0.4513
##
## Intercept: 5534 (368.9)
##
## Order selected 9 sigma^2 estimated as 44.62
library("tidyverse")
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ tibble 3.1.8 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ✔ purrr 0.3.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ dplyr::recode() masks car::recode()
## ✖ purrr::some() masks car::some()
# create a list to store the prediction for the next year average elo ratings
predict_result=list()
#index for the optimal order list
count=1
# loop to go over each team
for(i in team_name){
# create a list to store the each lag column like lag1, lag2...
group=list()
# each team's elo ratings dataframe
current_team=df[i]
# optimal order
counter<-opt_order[[count]]
# create lag column based on the optimal order
for(j in 1:counter){
# create the lag column using dplyr
current_team<-current_team %>%
dplyr::mutate("lag{j}":=lag(df[,i],n=j,default=NA))
# construct the lag column name string for later use and store it in the group list
temp=paste("lag",j,sep = "")
group=append(group,temp)
}
# go to the next optimal order for the next team
count=count+1
# construct the model formula to general model
mymodel<-as.formula(paste(i,paste(group,collapse = "+"),sep = "~"))
# use model lm function and model formula to generate the model
current_model=lm(mymodel,data=current_team)
# formmating
cat(paste("Team: ",i))
cat("\n")
# print the summary of the model
print(summary(current_model))
# get the prediction for the next year elo ratings
prediction=tail(current_team,n=1)
cat("The prediction for 2021 is the following\n")
# output the predicted next year elo ratings
print(predict(current_model,prediction))
# store the predicted result into list
predict_result=append(predict_result,predict(current_model,prediction))
cat("\n")
# run the durbinwatsonTest
print(durbinWatsonTest(current_model))
cat("\n")
cat("\n")
}
## Team: Orlando.Magic
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## 43.086 69.914 -32.955 -89.378 27.115 37.724 21.766 -44.748 -16.437 3.135
## 20 21
## -21.363 2.142
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3290.9290 4282.0434 -0.769 0.523
## lag1 1.2610 0.6431 1.961 0.189
## lag2 -0.3175 0.9162 -0.347 0.762
## lag3 -0.1058 0.9095 -0.116 0.918
## lag4 0.8743 1.0467 0.835 0.491
## lag5 0.3506 1.3237 0.265 0.816
## lag6 -0.6165 0.8770 -0.703 0.555
## lag7 0.4616 0.7373 0.626 0.595
## lag8 0.3090 0.8620 0.358 0.754
## lag9 0.9459 1.2936 0.731 0.541
##
## Residual standard error: 102.9 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.8621, Adjusted R-squared: 0.2418
## F-statistic: 1.39 on 9 and 2 DF, p-value: 0.487
##
## The prediction for 2021 is the following
## 21
## 1390.071
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1260496 1.660095 0.306
## Alternative hypothesis: rho != 0
##
##
## Team: Atlanta.Hawks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## -8.293 8.195 9.461 19.820 -74.501 50.263 20.562 3.956 -36.026 11.919
## 20 21
## 10.669 -16.025
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.481e+03 1.083e+03 2.291 0.149
## lag1 2.218e-01 5.297e-01 0.419 0.716
## lag2 1.476e-01 6.392e-01 0.231 0.839
## lag3 -4.475e-01 5.066e-01 -0.883 0.470
## lag4 -1.623e-01 8.688e-01 -0.187 0.869
## lag5 -9.941e-03 6.785e-01 -0.015 0.990
## lag6 5.228e-01 4.542e-01 1.151 0.369
## lag7 -6.158e-01 8.803e-01 -0.700 0.557
## lag8 2.043e-01 1.548e+00 0.132 0.907
## lag9 -5.410e-01 1.084e+00 -0.499 0.667
##
## Residual standard error: 73.97 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.8818, Adjusted R-squared: 0.3501
## F-statistic: 1.658 on 9 and 2 DF, p-value: 0.4321
##
## The prediction for 2021 is the following
## 21
## 1521.971
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.4134718 2.797194 0.644
## Alternative hypothesis: rho != 0
##
##
## Team: Brooklyn.Nets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17
## 9.45887 -5.16918 -9.47917 -0.00906 1.70910 24.50993 -13.77624 -33.76094
## 18 19 20 21
## 37.81599 9.09800 -45.22329 24.82601
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5879.20147 1973.19697 2.980 0.0966 .
## lag1 -0.76487 0.60714 -1.260 0.3348
## lag2 -0.31346 0.58533 -0.536 0.6459
## lag3 -0.58246 0.43639 -1.335 0.3136
## lag4 -0.66939 0.53270 -1.257 0.3358
## lag5 -0.61944 0.60822 -1.018 0.4156
## lag6 -0.09449 0.51676 -0.183 0.8718
## lag7 0.32987 0.40974 0.805 0.5053
## lag8 0.06185 0.35770 0.173 0.8786
## lag9 -0.51355 0.31472 -1.632 0.2443
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 56.19 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9359, Adjusted R-squared: 0.6473
## F-statistic: 3.243 on 9 and 2 DF, p-value: 0.2579
##
## The prediction for 2021 is the following
## 21
## 1554.036
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.3638659 2.615941 0.592
## Alternative hypothesis: rho != 0
##
##
## Team: Toronto.Raptors
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -109.33 -30.75 12.38 41.02 83.08
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 521.32031 286.07583 1.822 0.08983 .
## lag1 0.87755 0.25440 3.450 0.00391 **
## lag2 -0.02344 0.35904 -0.065 0.94888
## lag3 -0.19932 0.28243 -0.706 0.49193
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 66.49 on 14 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.6588, Adjusted R-squared: 0.5857
## F-statistic: 9.011 on 3 and 14 DF, p-value: 0.001416
##
## The prediction for 2021 is the following
## 21
## 1628.819
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.01541888 1.868053 0.568
## Alternative hypothesis: rho != 0
##
##
## Team: New.York.Knicks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -63.320 -13.610 -1.604 17.710 81.321
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4166.90433 1084.72628 3.841 0.00854 **
## lag1 0.24370 0.29564 0.824 0.44130
## lag2 -0.43890 0.32414 -1.354 0.22450
## lag3 -0.45238 0.32738 -1.382 0.21628
## lag4 0.06009 0.33736 0.178 0.86449
## lag5 -0.22152 0.33195 -0.667 0.52937
## lag6 -0.51931 0.33107 -1.569 0.16780
## lag7 -0.59425 0.33553 -1.771 0.12694
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 57.18 on 6 degrees of freedom
## (7 observations deleted due to missingness)
## Multiple R-squared: 0.7636, Adjusted R-squared: 0.4879
## F-statistic: 2.769 on 7 and 6 DF, p-value: 0.1177
##
## The prediction for 2021 is the following
## 21
## 1479.568
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1293712 2.247181 0.926
## Alternative hypothesis: rho != 0
##
##
## Team: Dallas.Mavericks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -52.839 -24.192 -5.515 14.407 83.610
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 85.29450 404.03740 0.211 0.83704
## lag1 1.07295 0.26939 3.983 0.00259 **
## lag2 -0.88049 0.39620 -2.222 0.05050 .
## lag3 0.49677 0.41936 1.185 0.26356
## lag4 0.26618 0.37030 0.719 0.48870
## lag5 -0.02313 0.38972 -0.059 0.95385
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 50.09 on 10 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.7866, Adjusted R-squared: 0.6798
## F-statistic: 7.37 on 5 and 10 DF, p-value: 0.003875
##
## The prediction for 2021 is the following
## 21
## 1537.109
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1438985 2.246477 0.922
## Alternative hypothesis: rho != 0
##
##
## Team: Houston.Rockets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -66.470 -40.707 8.202 35.983 112.950
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2874.86313 1016.48613 2.828 0.0222 *
## lag1 0.38293 0.38574 0.993 0.3499
## lag2 -0.39509 0.46644 -0.847 0.4216
## lag3 -0.08973 0.49966 -0.180 0.8619
## lag4 -0.68869 0.59113 -1.165 0.2776
## lag5 0.74495 0.48896 1.524 0.1661
## lag6 -0.78395 0.42491 -1.845 0.1023
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 64.99 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.5266, Adjusted R-squared: 0.1716
## F-statistic: 1.483 on 6 and 8 DF, p-value: 0.2953
##
## The prediction for 2021 is the following
## 21
## 1453.666
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.05963411 1.744307 0.404
## Alternative hypothesis: rho != 0
##
##
## Team: San.Antonio.Spurs
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -62.496 -25.699 -3.759 12.931 77.660
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1897.89288 747.43059 2.539 0.02598 *
## lag1 0.87953 0.24733 3.556 0.00395 **
## lag2 -0.29057 0.35733 -0.813 0.43196
## lag3 0.08296 0.35409 0.234 0.81871
## lag4 -0.81052 0.37615 -2.155 0.05219 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 43.9 on 12 degrees of freedom
## (4 observations deleted due to missingness)
## Multiple R-squared: 0.7504, Adjusted R-squared: 0.6671
## F-statistic: 9.017 on 4 and 12 DF, p-value: 0.001332
##
## The prediction for 2021 is the following
## 21
## 1510.932
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.008788928 1.906495 0.608
## Alternative hypothesis: rho != 0
##
##
## Team: Chicago.Bulls
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 9 10 11 12 13 14 15 16 17 18
## -26.985 -50.137 93.793 38.838 -52.155 59.184 11.774 -44.477 -6.178 -10.167
## 19 20 21
## -3.704 -8.636 -1.151
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1009.99713 711.36149 1.420 0.2287
## lag1 1.08087 0.38144 2.834 0.0472 *
## lag2 -0.56190 0.46940 -1.197 0.2974
## lag3 0.33691 0.53390 0.631 0.5623
## lag4 -0.28254 0.53264 -0.530 0.6239
## lag5 0.10485 0.44169 0.237 0.8240
## lag6 0.01854 0.46693 0.040 0.9702
## lag7 -0.64652 0.48053 -1.345 0.2497
## lag8 0.27852 0.37601 0.741 0.5000
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 74.36 on 4 degrees of freedom
## (8 observations deleted due to missingness)
## Multiple R-squared: 0.8218, Adjusted R-squared: 0.4655
## F-statistic: 2.306 on 8 and 4 DF, p-value: 0.2188
##
## The prediction for 2021 is the following
## 21
## 1427.732
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1911908 2.349398 0.602
## Alternative hypothesis: rho != 0
##
##
## Team: Utah.Jazz
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 9 10 11 12 13 14 15 16 17 18
## 10.613 35.174 -37.461 -31.698 24.178 -28.159 7.206 -1.536 27.261 -33.596
## 19 20 21
## -36.864 17.282 47.600
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3546.11609 2069.02078 1.714 0.162
## lag1 0.23275 0.48364 0.481 0.655
## lag2 -0.23644 0.45628 -0.518 0.632
## lag3 -0.15759 0.48068 -0.328 0.759
## lag4 -0.20252 0.46852 -0.432 0.688
## lag5 -0.48159 0.50128 -0.961 0.391
## lag6 0.03393 0.46183 0.073 0.945
## lag7 -0.70202 0.41187 -1.704 0.163
## lag8 0.19628 0.40905 0.480 0.656
##
## Residual standard error: 52.4 on 4 degrees of freedom
## (8 observations deleted due to missingness)
## Multiple R-squared: 0.8127, Adjusted R-squared: 0.438
## F-statistic: 2.169 on 8 and 4 DF, p-value: 0.237
##
## The prediction for 2021 is the following
## 21
## 1598.861
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.08664652 1.95678 0.578
## Alternative hypothesis: rho != 0
##
##
## Team: Portland.Trailblazers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## -24.239 32.062 18.404 -57.122 27.390 8.374 -12.573 -8.889 -8.263 16.620
## 20 21
## 9.453 -1.217
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.476e+03 1.514e+03 1.635 0.244
## lag1 -1.902e-01 6.571e-01 -0.290 0.799
## lag2 -6.522e-01 4.416e-01 -1.477 0.278
## lag3 -3.685e-02 5.901e-01 -0.062 0.956
## lag4 6.018e-02 4.950e-01 0.122 0.914
## lag5 1.058e-01 4.786e-01 0.221 0.846
## lag6 -2.094e-01 4.940e-01 -0.424 0.713
## lag7 4.272e-01 4.959e-01 0.862 0.480
## lag8 9.713e-03 5.951e-01 0.016 0.988
## lag9 -1.045e-01 3.748e-01 -0.279 0.807
##
## Residual standard error: 57.92 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.712, Adjusted R-squared: -0.5841
## F-statistic: 0.5493 on 9 and 2 DF, p-value: 0.7832
##
## The prediction for 2021 is the following
## 21
## 1527.184
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.3704038 2.653024 0.58
## Alternative hypothesis: rho != 0
##
##
## Team: Golden.State.Warriors
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 9 10 11 12 13 14 15 16 17 18
## -11.828 -49.272 -24.610 43.017 39.640 -5.591 19.327 -44.516 4.074 32.786
## 19 20 21
## 75.693 -95.775 17.055
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -433.33847 670.54649 -0.646 0.553
## lag1 0.49477 0.37997 1.302 0.263
## lag2 0.43384 0.52799 0.822 0.457
## lag3 0.03316 0.52136 0.064 0.952
## lag4 -0.57875 0.49947 -1.159 0.311
## lag5 -0.09252 0.48631 -0.190 0.858
## lag6 -0.15482 0.52731 -0.294 0.784
## lag7 0.23949 0.53850 0.445 0.680
## lag8 0.97248 0.47930 2.029 0.112
##
## Residual standard error: 79.48 on 4 degrees of freedom
## (8 observations deleted due to missingness)
## Multiple R-squared: 0.9122, Adjusted R-squared: 0.7365
## F-statistic: 5.192 on 8 and 4 DF, p-value: 0.06448
##
## The prediction for 2021 is the following
## 21
## 1446.276
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.2056957 2.394342 0.82
## Alternative hypothesis: rho != 0
##
##
## Team: Memphis.Grizzlies
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17
## 0.12159 -0.88427 1.16064 -0.16331 -0.35559 -0.34525 1.05033 0.08741
## 18 19 20 21
## -1.22601 0.05672 1.61950 -1.12177
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1398.65662 37.87402 36.929 0.000732 ***
## lag1 0.22436 0.02098 10.695 0.008629 **
## lag2 0.52586 0.02322 22.647 0.001944 **
## lag3 -0.47810 0.02635 -18.146 0.003023 **
## lag4 -0.60634 0.03405 -17.806 0.003139 **
## lag5 0.27788 0.02906 9.561 0.010763 *
## lag6 0.13213 0.03271 4.040 0.056162 .
## lag7 -0.17474 0.02308 -7.570 0.017007 *
## lag8 -0.38954 0.02556 -15.238 0.004279 **
## lag9 0.58084 0.02007 28.936 0.001192 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.111 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9999, Adjusted R-squared: 0.9992
## F-statistic: 1620 on 9 and 2 DF, p-value: 0.0006169
##
## The prediction for 2021 is the following
## 21
## 1528.324
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.3718603 2.600901 0.676
## Alternative hypothesis: rho != 0
##
##
## Team: Philadelphia.76ers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17
## -31.6444 56.6754 -13.3048 44.9596 -51.8601 16.8540 -19.0703 -4.1119
## 18 19 20 21
## 11.4159 -5.6791 -0.9383 -3.2960
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 465.1192 1339.2229 0.347 0.762
## lag1 1.3727 0.5185 2.648 0.118
## lag2 -1.5085 0.8294 -1.819 0.211
## lag3 0.9408 1.0625 0.886 0.469
## lag4 -0.9177 1.1483 -0.799 0.508
## lag5 0.1059 1.2331 0.086 0.939
## lag6 0.2476 1.2089 0.205 0.857
## lag7 -0.5599 0.9581 -0.584 0.618
## lag8 0.6490 0.9878 0.657 0.579
## lag9 0.3165 0.5151 0.614 0.602
##
## Residual standard error: 70.5 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9498, Adjusted R-squared: 0.7241
## F-statistic: 4.208 on 9 and 2 DF, p-value: 0.2067
##
## The prediction for 2021 is the following
## 21
## 1600.888
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.6737935 3.245756 0.63
## Alternative hypothesis: rho != 0
##
##
## Team: Boston.Celtics
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.627 -7.712 3.388 15.393 48.284
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.017e+03 6.231e+02 6.446 0.00066 ***
## lag1 7.110e-03 1.658e-01 0.043 0.96719
## lag2 -4.211e-01 1.688e-01 -2.495 0.04684 *
## lag3 -7.518e-03 1.903e-01 -0.040 0.96977
## lag4 -4.380e-01 1.652e-01 -2.652 0.03793 *
## lag5 -2.072e-01 1.784e-01 -1.161 0.28959
## lag6 -5.501e-01 1.734e-01 -3.172 0.01928 *
## lag7 3.276e-02 1.586e-01 0.207 0.84319
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 39.52 on 6 degrees of freedom
## (7 observations deleted due to missingness)
## Multiple R-squared: 0.9051, Adjusted R-squared: 0.7944
## F-statistic: 8.176 on 7 and 6 DF, p-value: 0.01026
##
## The prediction for 2021 is the following
## 21
## 1599.358
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1518778 1.490741 0.294
## Alternative hypothesis: rho != 0
##
##
## Team: Cleveland.Cavaliers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## 106.516 -75.357 65.752 -18.947 46.459 -2.458 23.623 -40.379 -16.263 7.556
## 20 21
## -29.321 -67.181
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5112.0209 3926.7469 1.302 0.323
## lag1 0.3361 0.5533 0.607 0.605
## lag2 -0.6242 0.4884 -1.278 0.330
## lag3 -0.2406 0.6843 -0.352 0.759
## lag4 -0.7476 0.5763 -1.297 0.324
## lag5 -0.2722 0.7882 -0.345 0.763
## lag6 -0.2299 0.5975 -0.385 0.738
## lag7 -0.3262 0.6203 -0.526 0.651
## lag8 0.1527 0.5311 0.288 0.801
## lag9 -0.4456 0.4882 -0.913 0.458
##
## Residual standard error: 126 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.8734, Adjusted R-squared: 0.3036
## F-statistic: 1.533 on 9 and 2 DF, p-value: 0.4562
##
## The prediction for 2021 is the following
## 21
## 1428.026
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.4393673 2.379305 0.886
## Alternative hypothesis: rho != 0
##
##
## Team: Charlotte.Hornets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -127.020 -44.501 4.702 55.194 73.284
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1072.0092 293.3040 3.655 0.00214 **
## lag1 0.6590 0.2224 2.963 0.00916 **
## lag2 -0.4131 0.2017 -2.048 0.05739 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 61.01 on 16 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.3621, Adjusted R-squared: 0.2823
## F-statistic: 4.541 on 2 and 16 DF, p-value: 0.02743
##
## The prediction for 2021 is the following
## 21
## 1383.525
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.02894974 1.962441 0.752
## Alternative hypothesis: rho != 0
##
##
## Team: Miami.Heat
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## -12.459 26.631 -13.723 -17.586 45.572 -23.775 -5.936 17.536 -16.960 6.690
## 20 21
## 17.259 -23.248
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3953.30818 1670.63252 2.366 0.142
## lag1 -0.09548 0.62626 -0.152 0.893
## lag2 0.19911 0.39078 0.510 0.661
## lag3 -0.45117 0.28055 -1.608 0.249
## lag4 -0.03965 0.39720 -0.100 0.930
## lag5 -0.47604 0.33883 -1.405 0.295
## lag6 -0.39000 0.40016 -0.975 0.433
## lag7 0.29047 0.31832 0.913 0.458
## lag8 -0.33257 0.41366 -0.804 0.506
## lag9 -0.23388 0.39612 -0.590 0.615
##
## Residual standard error: 52.52 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9301, Adjusted R-squared: 0.6157
## F-statistic: 2.958 on 9 and 2 DF, p-value: 0.2781
##
## The prediction for 2021 is the following
## 21
## 1560.261
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.5437965 2.961501 0.478
## Alternative hypothesis: rho != 0
##
##
## Team: Oklahoma.City.Thunder
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## -3.343 -1.018 19.622 -16.791 -11.618 26.673 -0.207 -14.547 -13.400 21.903
## 20 21
## 32.434 -39.708
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2765.64610 607.57177 4.552 0.045 *
## lag1 -0.20709 0.31352 -0.661 0.577
## lag2 0.32214 0.29646 1.087 0.391
## lag3 0.08138 0.26817 0.303 0.790
## lag4 -0.30423 0.27355 -1.112 0.382
## lag5 -0.59861 0.30271 -1.978 0.187
## lag6 0.42568 0.24042 1.771 0.219
## lag7 0.03919 0.26162 0.150 0.895
## lag8 -0.43891 0.25309 -1.734 0.225
## lag9 -0.07933 0.23543 -0.337 0.768
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 50.13 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9241, Adjusted R-squared: 0.5825
## F-statistic: 2.705 on 9 and 2 DF, p-value: 0.299
##
## The prediction for 2021 is the following
## 21
## 1465.17
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.2267425 2.1375 0.844
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Lakers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## 18.450 -17.816 -11.321 25.816 -20.411 3.817 6.565 2.730 -3.688 -29.192
## 20 21
## 35.093 -10.043
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 627.45354 585.08022 1.072 0.396
## lag1 0.16657 0.38398 0.434 0.707
## lag2 0.66368 0.48623 1.365 0.306
## lag3 0.04880 0.57908 0.084 0.941
## lag4 -0.67473 0.50585 -1.334 0.314
## lag5 0.03705 0.55920 0.066 0.953
## lag6 0.17710 0.61046 0.290 0.799
## lag7 -0.54611 0.46542 -1.173 0.361
## lag8 0.24658 0.37409 0.659 0.578
## lag9 0.43650 0.39064 1.117 0.380
##
## Residual standard error: 45.46 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9805, Adjusted R-squared: 0.8926
## F-statistic: 11.16 on 9 and 2 DF, p-value: 0.0849
##
## The prediction for 2021 is the following
## 21
## 1629.771
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.5470077 2.98723 0.04
## Alternative hypothesis: rho != 0
##
##
## Team: Denver.Nuggets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -90.587 -17.687 -4.533 23.024 67.624
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 990.68086 384.88584 2.574 0.02770 *
## lag1 1.01817 0.27546 3.696 0.00413 **
## lag2 -0.56239 0.36279 -1.550 0.15214
## lag3 0.02476 0.28639 0.086 0.93281
## lag4 0.18452 0.26319 0.701 0.49923
## lag5 -0.30728 0.19439 -1.581 0.14502
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 43.69 on 10 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.6956, Adjusted R-squared: 0.5434
## F-statistic: 4.57 on 5 and 10 DF, p-value: 0.0198
##
## The prediction for 2021 is the following
## 21
## 1589.593
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1386837 2.249466 0.9
## Alternative hypothesis: rho != 0
##
##
## Team: Phoenix.Suns
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -151.253 -77.410 -8.986 55.595 183.052
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 509.1778 272.8555 1.866 0.07841 .
## lag1 0.6631 0.1806 3.672 0.00175 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 92.02 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.4282, Adjusted R-squared: 0.3964
## F-statistic: 13.48 on 1 and 18 DF, p-value: 0.001746
##
## The prediction for 2021 is the following
## 21
## 1445.768
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1435297 1.477901 0.142
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Clippers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## -3.181 -31.327 40.661 0.787 -20.714 -12.292 19.182 36.117 -24.687 -45.787
## 20 21
## 43.009 -1.768
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 399.80509 700.17143 0.571 0.626
## lag1 0.47556 0.51880 0.917 0.456
## lag2 0.33891 0.64844 0.523 0.653
## lag3 -0.03547 0.62637 -0.057 0.960
## lag4 -0.38935 0.63691 -0.611 0.603
## lag5 -0.04467 0.65898 -0.068 0.952
## lag6 0.21674 0.62486 0.347 0.762
## lag7 0.25983 0.58662 0.443 0.701
## lag8 -0.16153 0.48663 -0.332 0.771
## lag9 0.11272 0.42446 0.266 0.815
##
## Residual standard error: 68.76 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9143, Adjusted R-squared: 0.5286
## F-statistic: 2.37 on 9 and 2 DF, p-value: 0.3318
##
## The prediction for 2021 is the following
## 21
## 1634.569
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.2382829 2.475166 0.75
## Alternative hypothesis: rho != 0
##
##
## Team: Washington.Wizards
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17
## 0.5221 5.9482 -13.4071 -0.3220 11.1437 5.3452 -16.1152 10.1718
## 18 19 20 21
## -14.0155 14.7946 2.5594 -6.6252
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2613.95670 1316.10112 1.986 0.1854
## lag1 0.86593 0.26250 3.299 0.0809 .
## lag2 -0.55653 0.33951 -1.639 0.2428
## lag3 0.26694 0.40086 0.666 0.5740
## lag4 -0.37120 0.30510 -1.217 0.3478
## lag5 -0.56374 0.36683 -1.537 0.2642
## lag6 -0.09296 0.19922 -0.467 0.6867
## lag7 0.39385 0.24721 1.593 0.2521
## lag8 -0.49119 0.23119 -2.125 0.1676
## lag9 -0.27685 0.29875 -0.927 0.4519
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24.47 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9856, Adjusted R-squared: 0.9208
## F-statistic: 15.21 on 9 and 2 DF, p-value: 0.0632
##
## The prediction for 2021 is the following
## 21
## 1418.868
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.4973467 2.957801 0.946
## Alternative hypothesis: rho != 0
##
##
## Team: Detroit.Pistons
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 9 10 11 12 13 14 15 16 17 18
## 4.692 -5.494 -8.677 27.502 10.099 -16.436 -28.473 36.445 -25.875 41.688
## 19 20 21
## 27.129 -22.583 -40.017
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 743.8335 475.6279 1.564 0.1929
## lag1 0.7351 0.2837 2.591 0.0606 .
## lag2 -0.3741 0.3480 -1.075 0.3428
## lag3 0.3139 0.2946 1.065 0.3467
## lag4 -0.2870 0.2736 -1.049 0.3534
## lag5 0.1826 0.2854 0.640 0.5570
## lag6 -0.3727 0.3201 -1.164 0.3091
## lag7 0.1043 0.3317 0.314 0.7689
## lag8 0.1706 0.2635 0.647 0.5527
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 46.5 on 4 degrees of freedom
## (8 observations deleted due to missingness)
## Multiple R-squared: 0.7852, Adjusted R-squared: 0.3557
## F-statistic: 1.828 on 8 and 4 DF, p-value: 0.2932
##
## The prediction for 2021 is the following
## 21
## 1401.877
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1473349 2.106992 0.484
## Alternative hypothesis: rho != 0
##
##
## Team: Indiana.Pacers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -89.603 -28.607 -1.564 36.577 54.630
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1579.6909 481.3800 3.282 0.00656 **
## lag1 0.3621 0.2445 1.481 0.16434
## lag2 0.1419 0.2616 0.542 0.59748
## lag3 -0.2554 0.2603 -0.981 0.34598
## lag4 -0.2929 0.2442 -1.199 0.25352
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 47.88 on 12 degrees of freedom
## (4 observations deleted due to missingness)
## Multiple R-squared: 0.4788, Adjusted R-squared: 0.3051
## F-statistic: 2.756 on 4 and 12 DF, p-value: 0.07764
##
## The prediction for 2021 is the following
## 21
## 1536.01
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.07777077 1.801042 0.526
## Alternative hypothesis: rho != 0
##
##
## Team: Minnesota.Timberwolves
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17 18 19
## 22.978 -37.183 -6.050 26.090 15.351 -36.063 13.106 2.456 -9.974 7.081
## 20 21
## 5.049 -2.842
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2779.50199 1476.27590 1.883 0.2004
## lag1 0.41826 0.32332 1.294 0.3250
## lag2 0.02937 0.44606 0.066 0.9535
## lag3 -1.39401 0.42551 -3.276 0.0819 .
## lag4 0.94217 0.58040 1.623 0.2460
## lag5 0.06706 0.34713 0.193 0.8647
## lag6 -1.06425 0.44976 -2.366 0.1416
## lag7 -0.22445 0.36084 -0.622 0.5974
## lag8 1.63223 0.84573 1.930 0.1934
## lag9 -1.36294 0.45213 -3.014 0.0947 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 47.57 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.941, Adjusted R-squared: 0.6757
## F-statistic: 3.546 on 9 and 2 DF, p-value: 0.2393
##
## The prediction for 2021 is the following
## 21
## 1337.113
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.3214432 2.524416 0.498
## Alternative hypothesis: rho != 0
##
##
## Team: Milwaukee.Bucks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -178.289 -30.933 -4.362 27.501 158.328
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 449.6498 266.9548 1.684 0.10937
## lag1 0.6983 0.1797 3.885 0.00108 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 72.82 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.4561, Adjusted R-squared: 0.4259
## F-statistic: 15.09 on 1 and 18 DF, p-value: 0.001085
##
## The prediction for 2021 is the following
## 21
## 1646.317
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.0415015 1.910716 0.726
## Alternative hypothesis: rho != 0
##
##
## Team: Sacramento.Kings
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17
## 16.8227 -18.1093 -15.6240 12.6885 10.2927 -16.6762 24.5996 0.2709
## 18 19 20 21
## -45.5850 22.8941 14.7130 -6.2869
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2328.83270 1471.64082 1.582 0.254
## lag1 -0.01771 0.62149 -0.029 0.980
## lag2 0.04696 0.45687 0.103 0.928
## lag3 -0.50203 0.46120 -1.089 0.390
## lag4 0.13712 0.66529 0.206 0.856
## lag5 0.13065 0.61004 0.214 0.850
## lag6 -0.64522 0.59598 -1.083 0.392
## lag7 0.50420 0.65465 0.770 0.522
## lag8 0.06343 0.69507 0.091 0.936
## lag9 -0.36745 0.49821 -0.738 0.538
##
## Residual standard error: 49.31 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.7678, Adjusted R-squared: -0.2771
## F-statistic: 0.7348 on 9 and 2 DF, p-value: 0.6955
##
## The prediction for 2021 is the following
## 21
## 1446.737
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.3035296 2.540742 0.118
## Alternative hypothesis: rho != 0
##
##
## Team: New.Orleans.Pelicans
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## 10 11 12 13 14 15 16 17
## -1.7506 7.4906 -1.6415 -7.1924 7.1048 4.5666 -7.9146 1.2695
## 18 19 20 21
## -0.1136 0.2161 10.9003 -12.9353
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5533.93275 903.61367 6.124 0.0256 *
## lag1 -0.46855 0.21848 -2.145 0.1652
## lag2 -0.32049 0.12173 -2.633 0.1190
## lag3 -0.24454 0.17080 -1.432 0.2886
## lag4 -0.04189 0.11133 -0.376 0.7429
## lag5 -0.59298 0.12708 -4.666 0.0430 *
## lag6 -0.54979 0.10103 -5.442 0.0321 *
## lag7 0.11901 0.11520 1.033 0.4101
## lag8 -0.20518 0.11236 -1.826 0.2094
## lag9 -0.45129 0.14782 -3.053 0.0926 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 16.36 on 2 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.9753, Adjusted R-squared: 0.864
## F-statistic: 8.766 on 9 and 2 DF, p-value: 0.1065
##
## The prediction for 2021 is the following
## 21
## 1499.124
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.4058042 2.493356 0.522
## Alternative hypothesis: rho != 0
# convert list to matrix
predict_result=do.call(rbind, predict_result)
# rename column name
colnames(predict_result)="Predict"
# add team name
predict_result=cbind(team_name,predict_result)
# convert matrix to dataframe
predict_result=as.data.frame(predict_result)
# remove row name
predict_result = predict_result %>% `rownames<-`( NULL )
predict_result
## team_name Predict
## 1 Orlando.Magic 1390.07126942078
## 2 Atlanta.Hawks 1521.97140846065
## 3 Brooklyn.Nets 1554.03594903058
## 4 Toronto.Raptors 1628.81857631474
## 5 New.York.Knicks 1479.5675913124
## 6 Dallas.Mavericks 1537.10852982091
## 7 Houston.Rockets 1453.66626037168
## 8 San.Antonio.Spurs 1510.93176491456
## 9 Chicago.Bulls 1427.73213753544
## 10 Utah.Jazz 1598.86081444179
## 11 Portland.Trailblazers 1527.18381011028
## 12 Golden.State.Warriors 1446.27563367298
## 13 Memphis.Grizzlies 1528.32432086334
## 14 Philadelphia.76ers 1600.88776990946
## 15 Boston.Celtics 1599.35754871597
## 16 Cleveland.Cavaliers 1428.0258114195
## 17 Charlotte.Hornets 1383.52479413362
## 18 Miami.Heat 1560.26145216225
## 19 Oklahoma.City.Thunder 1465.16989285989
## 20 Los.Angeles.Lakers 1629.77056559193
## 21 Denver.Nuggets 1589.59252061288
## 22 Phoenix.Suns 1445.76839336782
## 23 Los.Angeles.Clippers 1634.56927947088
## 24 Washington.Wizards 1418.8684880605
## 25 Detroit.Pistons 1401.87711993017
## 26 Indiana.Pacers 1536.00965953525
## 27 Minnesota.Timberwolves 1337.11275427319
## 28 Milwaukee.Bucks 1646.31737219909
## 29 Sacramento.Kings 1446.73745745777
## 30 New.Orleans.Pelicans 1499.12426646209